from utils import xprimes

MAX = 1000000
primes = set([str(i) for i in xprimes(MAX)])
circulars = set()

for str in primes:
    rotations = set()
    for j in range(len(str)):
        rotations.add(str[j:] + str[:j])
    if len(rotations - primes) == 0:
        circulars |= rotations

print len(circulars)

